import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== $Lazy
const $cache 			= $Lazy.file(()=>import('#private/cache-api'))
const $time 			= $Lazy.file(()=>import('@com/utils/time'))
const Title				= $Lazy.load(()=>import('#tp/title/title'))
const Table1 			= $Lazy.state(()=>import('@antd/table'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys: [],
		// 搜索表单列表
		forms: [
			{ label: '条码号',	name: 'spec_code' },
			{ label: '医院名称',	name: 'hosp_id',			type:'select',	loading:true },
			{ label: '录入时间',	names: ['start_date', 'end_date'], 	type:'date-range', 	loading:true },
		],
		content:[]
	}
	model = {}

	
	componentDidMount(){
		this.getSelect()
		$time.then(f=>{
			const arr = f.duration['2-0-24']()
			this.resetModel = { start_date: arr[0], end_date: arr[1], 'jz-time':arr }
			this.model = $fn.copy(this.resetModel)
			this.fetch()
		})
	}
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			$fn.setRow( forms, 'hosp_id', await f.getCache({ api:'hospital' }) )
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'specimen/doubleLog', {isIndex: true})
	controls = () => [
		Controls.back.call(this,{refresh:true} ),   				// 返回
	]
	
	// 表单
	cols = [
		{ title: '申请单条码',		dataIndex: 'spec_code', 		...$fn.table.spec_code },
		{ title: '送检单位', 		dataIndex: 'hosp_name', 		width: 200 },
		{ title: '操作人',			dataIndex: 'operator_name', 	...$fn.table.name },
		{ title: '操作时间', 		dataIndex: 'operator_at', 		...$fn.table.time },
		{ title: '描述',			dataIndex: 'title', 			width:180 },
	]
	cols1 = [
		{ title: '项目代码', 	dataIndex: 'kind_code',				width:100 },
		{ title: '项目名称', 	dataIndex: 'kind_name', 			width:180 },
	]
	render(){
		return (
			<>
				{/* 搜索 */}
				{ SearchForm.call(this, {timeStr:'2-0-24'}) }
				{/* 表格 */}
				{ Table.call(this, {type: 1, isIndex: true,	onRow: ({content}) => this.setState({content:[content]})} ) }
				<Title title='录入详情' style={{border:0,height:26}} />
				<div>
					<Table1
						simple
						idStr			= 'kind_id'
						cols			= { this.cols1 }
						data 			= { this.state.content  }
						onRef			= { ref => this.table = ref }
					/>
				</div>
			</>
		)
	}
}

export default Index